﻿using System;
using SapaFinance.Domain.Model;
using Xunit;

namespace SapaFinance.Tests
{
    public class MoneyTest
    {
        public static Money Create()
        {
            var payment = new Money(2.00m, new Rub());
            return payment;
        }
        [Fact]
        public void CheckMoneyAdd()
        {
            var p1 = Create();
            var p2 = Create();
            var p3 = new Money(4.00m, new Rub());
            Assert.Equal(p3.Amount, (p1 + p2).Amount);
        }

        [Fact]
        public void CheckMoneySub()
        {
            var p1 = Create();
            var p2 = Create();
            var p3 = new Money(0.00m, new Rub());
            Assert.Equal(p3.Amount, (p1 - p2).Amount);
        }

        [Fact]
        public void CheckMoneySubDiffClass()
        {
            var p1 = Create();
            var p2 = new Money(2.00m, new Eur());
            var ex = Assert.Throws<InvalidOperationException>(() => p1 - p2);
            Assert.Equal(ex.Message, "Can't exec math operation under different type class");
        }

        [Fact]
        public void CheckMoneyAddDiffClass()
        {
            var p1 = Create();
            var p2 = new Money(2.00m, new Eur());
            var ex = Assert.Throws<InvalidOperationException>(() => p1 + p2);
            Assert.Equal(ex.Message, "Can't exec math operation under different type class");
        }

        [Fact]
        public void CheckMoneyEqual()
        {
            var p1 = Create();
            var p2 = Create();
            var p3 = new Money(2.00m, new Eur());
            var p4 = new Money(4.00m, new Rub());
            Assert.Equal(p1, p2);
            Assert.NotEqual(p1, p3);
            Assert.NotEqual(p1, p4);
            Assert.True(p1 == p2);
            Assert.True(p1 != p3);
            Assert.False(p1 == p3);
            Assert.False(p1 != p2);
            Assert.False(p1 == null);
        }
    }
}